﻿using System;
using System.Collections.Generic;
using System.Text;

namespace BusLineParser
{
    /// <summary>
    /// 公交线路信息实体
    /// </summary>
    internal class LineInfo :IComparable
    {
        #region 属性
              
        /// <summary>
        /// 线路名称,比如606
        /// </summary>
        public string LineNo { get; set; }
        /// <summary>
        /// 起点站
        /// </summary>
        public string Start { get; set; }
        /// <summary>
        /// 起点站首班时间(时间都以夏季为准)
        /// </summary>
        public string StartBeginTime { get; set; }
        /// <summary>
        /// 起点站末班车时间
        /// </summary>
        public string StartEndTime { get; set; }
        /// <summary>
        /// 终点站
        /// </summary>
        public string End { get; set; }
        /// <summary>
        /// 终点站首班车时间
        /// </summary>
        public string EndBeginTime { get; set; }
        /// <summary>
        /// 终点站末班车时间
        /// </summary>
        public string EndTime { get; set; }
        /// <summary>
        /// 线路类型,是否国营,私营等.
        /// </summary>
        public string LineType
        {
            get { return LineType; }//这样写看看会不会有问题哈.2008年9月12日10:09:57
            set { LineType = value; }
        }
        /// <summary>
        /// 非空调车价格
        /// </summary>
        public string NonAirconditionerPrice { get; set; }
        /// <summary>
        /// 空调车价格
        /// </summary>
        public string AirconditionerPrice { get; set; }

        private List<string> upLine = new List<string>();
        /// <summary>
        ///   上行线站点集合
        /// </summary>
        public List<string> UpLine
        {
            get { return upLine; }
        }

        private List<string> downLine = new List<string>();
        /// <summary>
        /// 下行线站点集合
        /// </summary>
        public List<string> DownLine
        {
            get { return downLine; }
        }
        /// <summary>
        /// 下行线路站点数
        /// </summary>
        public int DownLineCout
        {
            get { return this.downLine.Count; }
        }
        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }

        #endregion

        #region 方法


        /// <summary>
        /// 添加上行线路站点
        /// </summary>
        /// <param name="busStation">公交车站</param>
        public void AddUpLine(string busStation)
        {
            if (string.IsNullOrEmpty(busStation))
                throw new ArgumentNullException(busStation, "公交站点不得为空");

            this.upLine.Add(busStation);
        }

        /// <summary>
        /// 添加下行线路站点
        /// </summary>
        /// <param name="busStation">公交车站</param>
        public void AddDownLine(string busStation)
        {
            if (string.IsNullOrEmpty(busStation))
                throw new ArgumentNullException(busStation, "公交站点不得为空");

            this.downLine.Add(busStation);
        }
        /// <summary>
        /// 上行线路站点数
        /// </summary>
        /// <returns></returns>
        public int UpLineCount()
        {
            return this.upLine.Count;
        }
        /// <summary>
        /// 输出上行线,下行线线路
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("线路名称: ").Append(this.LineNo).Append("\r\n");
            sb.Append("运营路线: ").Append(this.Start).Append("<---->").Append(this.End).Append("\r\n");
            sb.Append("始发站时刻: ").Append(this.StartBeginTime).Append("--").Append(this.StartEndTime).Append("\r\n");
            sb.Append("终点站时刻: ").Append(this.EndBeginTime).Append("--").Append(this.EndTime).Append("\r\n");
            sb.Append("非空调车价格: ").Append(this.NonAirconditionerPrice).Append("\r\n");
            sb.Append("空调车价格: ").Append(this.AirconditionerPrice).Append("\r\n");

            sb.Append("上行线站点数:").Append(this.upLine.Count).Append("个 (*^__^*) ");
            foreach (string station in this.upLine)
            {
                sb.Append(station).Append("-->");
            }
            sb.Remove(sb.Length - 3, 3);
            sb.Append("\r\n");
            sb.Append("\r\n下行线站点数:").Append(this.downLine.Count).Append("个 (*^__^*) ");
            foreach (string station in this.downLine)
            {
                sb.Append(station).Append("-->");
            }
            sb.Remove(sb.Length - 3, 3);

            sb.Append("\r\n◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆\r\n\r\n");
            return sb.ToString();
        }
        /// <summary>
        /// 为塞班系统S60格式化输出,For '公交查询'
        /// </summary>
        /// <returns></returns>
        public string FormatbySymbian()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(this.LineNo).Append(",");
            sb.Append(this.Start).Append(",").Append(this.StartBeginTime).Append(",").Append(this.StartEndTime).Append(",");
            sb.Append(this.End).Append(",").Append(this.EndBeginTime).Append(",").Append(this.EndTime).Append(",");
            sb.Append("市公交").Append(",");
            foreach (string station in this.upLine)
            {
                sb.Append(station).Append("-");
            }
            sb.Remove(sb.Length - 1, 1).Append(",");
            foreach (string station in this.downLine)
            {
                sb.Append(station).Append("-");
            }
            sb.Remove(sb.Length - 1, 1).Append(",");
            sb.Append("  非空调车价格: ").Append(this.NonAirconditionerPrice)
                .Append("  开空调价格: ").Append(this.AirconditionerPrice);

            return sb.ToString();
        }
        #endregion

        #region IComparable Members

        public int CompareTo(object obj)
        {
            if (obj is LineInfo)
            {
                LineInfo otherLineInfo = (LineInfo)obj;
                try
                {
                    int other = int.Parse(otherLineInfo.LineNo);
                    int thisLine = int.Parse(this.LineNo);
                    return thisLine.CompareTo(other);
                }
                catch
                {
                    return this.LineNo.CompareTo(otherLineInfo.LineNo);
                }
            }
            else
            {
                throw new ArgumentException("object is not a LineInfo");
            }
        }

        #endregion
    }
}
